from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

# 数据库连接字符串
# SQLALCHEMY_DATABASE_URL = (
#     "mysql+mysqlconnector://mytool:5nBMP2rCsN7ciC6T@localhost:3306/mytool"
# )
SQLALCHEMY_DATABASE_URL = (
    "mysql+mysqlconnector://mytool:5nBMP2rCsN7ciC6T@8.137.71.236:3306/mytool"
)
# 创建数据库引擎，增加连接池设置
engine = create_engine(
    SQLALCHEMY_DATABASE_URL,
    pool_size=10,          # 连接池大小
    max_overflow=20,       # 超出连接池大小的连接数
    pool_pre_ping=True,    # 检查连接是否有效
    pool_recycle=3600,     # 连接回收时间（秒）
)
# 创建会话工厂
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
